package com.dwxt.cdms.exception;

import com.dwxt.common.base.BaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 自定义异常处理
 *
 * @author Kuang.JiaZhuo
 * @date 2020-09-05 16:30
 */
@ControllerAdvice
public class CustomExceptionHandler {
    private Logger logger = LoggerFactory.getLogger(CustomExceptionHandler.class);

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public BaseResult handleBindException(Exception e) {
        CustomException definedException = (CustomException) e;
        logger.error(definedException.getBaseResult().getMsg());
        return definedException.getBaseResult();
    }

}
